/**
 * Version: 2.16
 * set style中注释掉2行，是在ie10的兼容模式（IE7）下检查出不支持
 */ 
var UM_OB = new function () {
	hst			= 'http://www.uread.me';
	hs			= '';
	
	this.opn = function () {
            if (document.URL.match(/^http:\/\/|^https:\/\//i)) {
		//alert(navigator.userAgent);
		hs 	= get_selection_HTML();
		if (hs) {
			jsonp_call_server('init');
		} else {
			if (document.readyState == 'complete') {
				hs = get_all_HTML();
				jsonp_call_server('init');
			} else {
				create_error('当前网页尚未加载完毕，正在等待加载完成...', '或者您可以选中部分内容进行保存。');
				return false;
			}
		}
            } else {
              location.href = hst;  
            }
	}
	jsonp_call_server = function (a, b) {
		if (a == 'init' || a == 'logout') {
			create_error('', '正在连接服务器...');
			append_jsonp_script(hst+"/ie_jsonp_call.php?a="+a+"&time="+(+new Date));
		} else if (a == 'show_save') {
			create_error('', '正在连接服务器...');
			append_jsonp_script(hst+"/save.php?br=ie&time="+(+new Date));
		} else if (a == 'check_login') {
			append_jsonp_script(hst+"/ie_jsonp_call.php?a="+a+"&b="+b+"&time="+(+new Date));
		}
	}
	append_jsonp_script = function (url) {
		var jsonp_script = document.createElement('script');
		jsonp_script.setAttribute('charset', 'utf-8');
		jsonp_script.setAttribute('type', 	'text/javascript');
		jsonp_script.setAttribute('src', 		url);
		document.body.appendChild(jsonp_script);
	}
	this.jsonp_callback = function (json) {
		if (typeof(json) == 'string' && json == 'show_save') {
			jsonp_call_server('show_save');
		} else if (typeof(json) == 'string' && json == 'show_login') {
			create_login();
		} else if (typeof(json) == 'object' && json.nick) {
			create_tpl(json);
		}
	}
	create_login = function (dinto) {
		var c = create_bgfg();
		var ifr = document.getElementById('uReadMe_login_iframe');
		if (ifr) {
			ifr.removeNode(true);
		}
		ifr = document.createElement('iframe');
		set_style(ifr, {'display':'block', 'backgroundColor':'#FFF', 'width':'100%', 'height':'100%'});
		ifr.frameBorder = 0;
		ifr.setAttribute('src', 	hst+'/login.php?ureadmeiframe=1&dinto='+dinto+'&time='+(+new Date));
		ifr.setAttribute('id', 	'uReadMe_login_iframe');
		var times = 0;
		ifr.onreadystatechange = function () {
			if (ifr.readyState == 'complete') {
				if (dinto == 'weibo' || dinto == 'renren' || dinto == 'kaixin001' || dinto == 'qqwb' || times > 0) {
					jsonp_call_server('check_login', dinto);
				}
				times++;
			}
		}
		c.appendChild(ifr);
	}
	create_tpl = function (json) {
		var content = create_bgfg();
		
		// 登录用户的昵称
		var a = document.getElementById('uReadMe_nick');
		if (a) {
			a.appendChild(document.createTextNode(json.nick + ' ')); 	// 讨厌的IE在处理中英文字符时候总是差一个像素，加个空格暂时解决一下
		}
		// 退出的链接
		a = document.getElementById('uReadMe_exit');
		if (a) {
			a.appendChild(document.createTextNode('退出 ')); 	// 讨厌的IE在处理中英文字符时候总是差一个像素，加个空格暂时解决一下
		}
		// 已经登录的账号icon
		a = document.getElementById('uReadMe_is_login');
		if (a && json.is_login) {
			for (i=0; i<json.is_login.length; i++) {
				b = document.createElement('img');
				set_style(b, {'display':'inline-block', 'margin':'0 4px 0 0'});
				b.setAttribute('title',	json.is_login[i].name + '已经登录成功');
				b.setAttribute('src',	json.is_login[i].img);
				a.appendChild(b);
			}
		}
		// 未登录的账号icon和登陆提示和登陆链接
		a = document.getElementById('uReadMe_not_login');
		if (a && json.not_login && json.not_login.length>0) {
			for (i=0; i<json.not_login.length; i++) {
				b = document.createElement('img');
				set_style(b, {'display':'inline-block', 'margin':'0 4px 0 0'});
				b.setAttribute('title',	json.not_login[i].name + '授权过期，请重新登陆');
				b.setAttribute('src',	json.not_login[i].img);
				a.appendChild(b);
			}
//			<div style="position:absolute; text-align: left; top:22px;">
//				<img src="/images/arrow_tips_up.png" style="margin:0 0 -1px 5px; width:13px; height:7px;">
//				<div style="border:1px solid #CCA; background-color: #FFC; padding:10px 20px 20px 20px; white-space: nowrap;">
//					绑定账号的登录授权已过期
//					<{section name=i loop=$not_login}>
//						<a style="display:block; margin:10px 0 0 0;"><{$not_login[i].link}></a>
//					<{/section}>
//				</div>
//			</div>

			b = document.createElement('div');
			b.setAttribute('id',	'uReadMe_not_login_tips');
			set_style(b, {'position':'absolute', 'text-align':'left', 'top':'22px', 'left':(a.offsetLeft-3)+'px', 'zIndex':2147483647});
			c = document.createElement('img');
			set_style(c, {'margin':'0 0 -1px 5px', 'width':'13px', 'height':'7px'});
			c.setAttribute('src',	'http://uread.me/images/arrow_tips_up.png');
			b.appendChild(c);
			
			c = document.createElement('div');
			set_style(c, {'display':'block', 'border':'1px solid #CCA', 'backgroundColor':'#FFC', 'padding':'10px 20px', 'color':'#ACF'});
			c.appendChild(document.createTextNode('以下账号的登录授权已过期')); 
			for (i=0; i<json.not_login.length; i++) {
				d = document.createElement('img');
				set_style(d, {'border':'none', 'cursor':'pointer', 'display':'block', 'margin':'10px 0 0 0'});
				d.setAttribute('src',	json.not_login[i].login_img);
				d.setAttribute('id',	json.not_login[i].flag);
				d.onclick = function () {
					create_login(this.id);
				}
				c.appendChild(d);
			}
			d = document.createElement('div');
			set_style(d, {'display':'block', 'margin':'15px 0 0 0', 'text-align':'right'});
			e = document.createElement('a');
			set_style(e, {'color':'#ACF', 'text-decoration':'underline', 'cursor':'pointer'});
			e.appendChild(document.createTextNode('关闭')); 
			e.onclick = function () {
				document.getElementById('uReadMe_not_login_tips').style.display = 'none';
			}
			d.appendChild(e);
			c.appendChild(d);
			b.appendChild(c);
			a.appendChild(b);
		}
		
		// TITLE LINE ------------------------------------------------------------------------------------------------------------------------------------
		a = document.createElement('div');
		a.setAttribute('id',	'uReadMe_title');
		set_style(a, {'margin':'0px 20px', 'padding':'0px 20px', 'height':'65px', 'borderBottom':'1px dotted #CCC'});
		content.appendChild(a);
			// title
			var b = document.createElement('div');
			set_style(b, {'styleFloat':'left', 'minWidth':'40%', 'maxWidth':'60%', 'height':'21px', 'overflow':'hidden', 'overflowX':'hidden', 'overflowY':'hidden', 'fontSize':'18px', 'fontFamily':'微软雅黑', 'padding':'0', 'margin':'30px 0 0 0'});
			b.appendChild(document.createTextNode(document.title)); 
			a.appendChild(b);
			
			// title right
			var c = document.createElement('div');
			set_style(c, {'styleFloat':'left', 'width':'38%', 'padding':'0', 'margin':'20px 0 0 0'});
			a.appendChild(c);
			
			// save button
			d = document.createElement('div');
			d.setAttribute('id',	'uReadMe_save_button');
			d.appendChild(document.createTextNode('完成')); 
			set_style(d, {'styleFloat':'left', 'margin':'0 0 0 10px', 'padding':'5px 20px', 'fontSize':'18px', 'fontFamily':'微软雅黑', 'color':'#FFF', 'backgroundColor':'#69F', 'cursor':'pointer', 'borderTop':'1px solid #CCC', 'borderLeft':'1px solid #CCC', 'borderRight':'1px solid #333', 'borderBottom':'1px solid #333'});
			d.onclick = function () {
				save();
			}
			c.appendChild(d);

		// BODY LINE ------------------------------------------------------------------------------------------------------------------------------------
		var h = content.clientHeight - a.clientHeight - 20;
		a = document.createElement('div');				// body
		a.setAttribute('id',	'uReadMe_body');
		set_style(a, {'position':'relative','padding':'0', 'margin':'0', 'height':h+'px', 'overflow':'auto', 'overflowX':'hidden', 'overflowY':'auto'});
		content.appendChild(a);
			// 圈子行 ------------------------------------------------------------------------------------------------------------------------------------
			var b = document.createElement('div');
			set_style(b, {'position':'relative', 'margin':'0 40px', 'padding':'10px 0px 5px 0px', 'borderBottom':'1px dotted #CCC'});
			a.appendChild(b);
				// circle list ------------------------------------------------------------------------------------------------------------------------------------
				c = document.createElement('div');
				c.setAttribute('id',	'uReadMe_circle_list');
				set_style(c, {'position':'relative','margin':'0 0 0 110px', 'minHeight':'40px'});
				b.appendChild(c);
				// circle caption ------------------------------------------------------------------------------------------------------------------------------------
				b = document.createElement('div');
				set_style(b, {'position':'absolute', 'top':'11px', 'left':'-100px', 'color':'#777777', 'padding':'0', 'margin':'0', 'textAlign':'right', 'width':'100px'});
				b.appendChild(document.createTextNode('保存到阅读圈：')); 
				c.appendChild(b);
					// circle name ------------------------------------------------------------------------------------------------------------------------------------
					if (typeof(json.circles) == 'object' && json.circles.length>0) {		// 阅读圈
						for (i=0; i<json.circles.length; i++) {
							b = document.createElement('a');
							b.setAttribute('uReadMeId',	json.circles[i].id);
							set_style(b, {'display':'inline-block', 'fontSize':'14px', 'margin':'5px 10px 0 0', 'padding':'5px', 'textDecoration':'underline', 'cursor':'pointer'});
							if (json.circles[i].privacy == 'private') {
								b.style.color = '#851';
								b.setAttribute('uReadMeColor',	'#851');
								b.setAttribute('uReadMeSBG',	'#D82');
							} else {
								b.style.color = '#069';
								b.setAttribute('uReadMeColor',	'#069');
								b.setAttribute('uReadMeSBG',	'#69F');
							}
							b.appendChild(document.createTextNode(json.circles[i].name)); 
							b.onclick = function () {
								if (color2hex(this.style.backgroundColor) == 'transparent') {
									this.style.backgroundColor = this.attributes.uReadMeSBG.value;
									this.style.color = '#FFF';
								} else {
									this.style.backgroundColor = 'transparent';
									this.style.color = this.attributes.uReadMeColor.value;
								}
							}
							c.appendChild(b);
						}
						// 新建圈子 ------------------------------------------------------------------------------------------------------------------------------------
						b = document.createElement('a');
						b.setAttribute('id',	'uReadMe_new_circle_a');
						set_style(b, {'display':'inline-block', 'fontSize':'12px', 'color':'#060', 'margin':'5px 10px 0 0px', 'padding':'5px', 'textDecoration':'underline', 'cursor':'pointer'});
						b.appendChild(document.createTextNode('＋新建阅读圈')); 
						b.onclick = function () {
							var tmp = document.getElementById('uReadMe_new_circle_div');
							tmp.style.display = 'block';
							this.style.display = 'none';
						}
						c.appendChild(b);
						// 输入框 ------------------------------------------------------------------------------------------------------------------------------------
						var nc = document.createElement('div');
						nc.setAttribute('id',	'uReadMe_new_circle_div');
						set_style(nc, {'display':'none', 'position':'relative', 'border':'1px solid #EEE', 'backgroundColor':'#FAFAFA', 'width':'340px', 'height':'40px'});
						c.appendChild(nc);
						b = document.createElement('input');				// input folder name
						b.setAttribute('id',	'uReadMe_new_circle_name');
						b.setAttribute('type',	'text');
						b.setAttribute('maxLength',	20);
						set_style(b, {'position':'absolute', 'width':'110px', 'fontSize':'14px', 'border':'1px solid #AAA', 'padding':'2px', 'top':'10px', 'left':'20px'});
						nc.appendChild(b);
						b = document.createElement('input');
						b.setAttribute('id',	'uReadMe_new_circle_is_private');
						b.setAttribute('type',	'checkbox');
						set_style(b, {'position':'absolute', 'top':'14px', 'left':'138px'});
						nc.appendChild(b);
						b = document.createElement('span');
						set_style(b, {'position':'absolute', 'font-size':'12px', 'color':'#060', 'top':'18px', 'left':'158px', 'cursor':'pointer'});
						b.appendChild(document.createTextNode('私有')); 
						b.onclick = function () {
							var chk = document.getElementById('uReadMe_new_circle_is_private');
							if (chk.checked) {
								chk.checked = false;
							} else {
								chk.checked = true;
							}
						}
						nc.appendChild(b); 
						b = document.createElement('div');
						set_style(b, {'position':'absolute', 'padding':'5px 15px 3px 15px', 'fontSize':'14px', 'top':'5px', 'left':'210px', 'backgroundColor':'#060', 'color':'#FFF', 'borderTop':'1px solid #CCC', 'borderLeft':'1px solid #CCC', 'borderRight':'1px solid #060', 'borderBottom':'1px solid #060',  'cursor':'pointer'});
						b.appendChild(document.createTextNode('确定')); 
						b.onclick = function () {
							var nm = document.getElementById('uReadMe_new_circle_name').value;
							if (nm) {
								var na = document.getElementById('uReadMe_new_circle_a');
								var p = na.parentNode;
								na.style.display = 'none';
								document.getElementById('uReadMe_new_circle_div').style.display = 'none';

								var tmp = document.createElement('a');
								set_style(tmp, {'display':'inline-block', 'fontSize':'14px', 'color':'#FFF', 'backgroundColor':((document.getElementById('uReadMe_new_circle_is_private').checked) ? '#D82' : '#69F'), 'margin':'5px 10px 0 0', 'padding':'5px', 'textDecoration':'underline', 'cursor':'pointer'});
								tmp.appendChild(document.createTextNode(nm)); 
								tmp.onclick = function () {
									document.getElementById('uReadMe_new_circle_name').value = '';
									document.getElementById('uReadMe_new_circle_is_private').checked = false;
									document.getElementById('uReadMe_new_circle_a').style.display = 'inline-block';
									this.removeNode(true);
									//this.parentNode.removeChild(this);
								}
								p.appendChild(tmp);
							} else {
								alert('请填写圈子的名称');
							}
						}
						nc.appendChild(b);
						b = document.createElement('a');
						set_style(b, {'position':'absolute', 'padding':'0 10px', 'color':'#555', 'top':'17px', 'left':'280px', 'textDecoration':'underline', 'cursor':'pointer'});
						b.appendChild(document.createTextNode('取消')); 
						b.onclick = function () {
							document.getElementById('uReadMe_new_circle_name').value = '';
							document.getElementById('uReadMe_new_circle_is_private').checked = false;
							document.getElementById('uReadMe_new_circle_div').style.display = 'none';
							document.getElementById('uReadMe_new_circle_a').style.display = 'inline-block';
						}
						nc.appendChild(b);
					} else {
						var nc = document.createElement('div');
						nc.setAttribute('id',	'uReadMe_new_circle_div');
						set_style(nc, {'position':'relative', 'width':'210px', 'height':'34px', 'border':'1px solid #EEE', 'backgroundColor':'#FAFAFA'});
						c.appendChild(nc);
						b = document.createElement('input');				// input folder name
						b.setAttribute('id',	'uReadMe_new_circle_name');
						b.setAttribute('type',	'text');
						b.setAttribute('maxLength',	20);
						set_style(b, {'position':'absolute', 'width':'110px', 'fontSize':'14px', 'border':'1px solid #AAA', 'padding':'2px', 'top':'6px', 'left':'20px'});
						nc.appendChild(b);
						
						b = document.createElement('input');				// input checkbox is private
						b.setAttribute('id',	'uReadMe_new_circle_is_private');
						b.setAttribute('type',	'checkbox');
						b.setAttribute('value',	'1');
						set_style(b, {'position':'absolute', 'top':'10px', 'left':'145px'});
						nc.appendChild(b);
						
						b = document.createElement('div');
						set_style(b, {'position':'absolute', 'font-size':'12px', 'color':'#060', 'top':'14px', 'left':'163px', 'cursor':'pointer'});
						b.appendChild(document.createTextNode('私有')); 
						b.onclick = function () {
							var chk = document.getElementById('uReadMe_new_circle_is_private');
							if (chk.checked) {
								chk.checked = false;
							} else {
								chk.checked = true;
							}
						}
						nc.appendChild(b); 
					}
			// 好友行 ------------------------------------------------------------------------------------------------------------------------------------
			var b = document.createElement('div');				// friend
			set_style(b, {'position':'relative', 'margin':'0 40px', 'padding':'10px 0px 5px 0px', 'borderBottom':'1px dotted #CCC'});
			a.appendChild(b);
//				 friend list ------------------------------------------------------------------------------------------------------------------------------------
				c = document.createElement('div');
				c.setAttribute('id',	'uReadMe_friend_list');
				set_style(c, {'position':'relative', 'margin':'0 0 0 110px', 'minHeight':'40px'});
				b.appendChild(c);
				// friend caption ------------------------------------------------------------------------------------------------------------------------------------
				b = document.createElement('div');
				set_style(b, {'position':'absolute', 'top':'11px', 'left':'-100px', 'color':'#777777', 'padding':'0', 'margin':'0', 'textAlign':'right', 'width':'100px'});
				b.appendChild(document.createTextNode('推荐给好友：')); 
				c.appendChild(b);
					// friend name ------------------------------------------------------------------------------------------------------------------------------------
					if (typeof(json.friends) == 'object' && json.friends.length>0) {
						for (i=0; i<json.friends.length; i++) {
							b = document.createElement('a');			// title
							set_style(b, {'display':'inline-block', 'fontSize':'14px', 'color':'#069', 'margin':'5px 10px 0 0', 'padding':'5px', 'textDecoration':'underline', 'cursor':'pointer'});
							b.setAttribute('uReadMeId',	json.friends[i].id);
                                                        b.setAttribute('uReadMeSocials',	json.friends[i].socials);
							b.appendChild(document.createTextNode(json.friends[i].name)); 
							b.onclick = function () {
								if (color2hex(this.style.backgroundColor) == 'transparent') {
									this.style.backgroundColor = '#69F';
									this.style.color = '#FFF';
								} else {
									this.style.backgroundColor = 'transparent';
									this.style.color = '#069';
								}
							}
							b.onmouseover = function () {
								var a = this;
								uReadMe_TimeOut = setTimeout(  function () {float_social('show', a)}  , 300);
							}
							b.onmouseout = function () {
								clearTimeout(uReadMe_TimeOut);
								float_social('hide', this);
							}
							c.appendChild(b);
						}
					}
	}
	create_error = function (msg_red, msg_blue) {
		var c = create_bgfg();
		
		var d = document.createElement('div');
		set_style(d, {'padding':'100px 0 0 0'});
		c.appendChild(d);
		if (msg_red) {
			var e = document.createElement('div');
			set_style(e, {'fontSize':'32px', 'color':'#FA6', 'fontFamily':'微软雅黑,黑体', 'textAlign':'center', 'padding':'0 0 10px 0'});
			e.appendChild(document.createTextNode(msg_red)); 
			d.appendChild(e);
		}
		if (msg_blue) {
			var f = document.createElement('div');
			set_style(f, {'fontSize':'28px', 'color':'#ACF', 'fontFamily':'微软雅黑,黑体', 'textAlign':'center', 'padding':'0 0 10px 0'});
			f.appendChild(document.createTextNode(msg_blue)); 
			d.appendChild(f);
		}
	}
	create_bgfg = function () {
		close_layer();
		var a = document.createElement('div');
		a.setAttribute('id', 		'uReadMe_bg');
		set_style(a, {'backgroundColor':'#20292F', 'top':0, 'left':0, 'right':0, 'bottom':0, 'position':'fixed', 'zIndex':2147483647, 'filter':'Alpha(Opacity=70)'});
		a.onclick 					= function () { close_layer(); }
		document.body.appendChild(a);
		a = document.createElement('div');
		a.setAttribute('id', 		'uReadMe_fg');
		set_style(a, {'backgroundColor':'#F9F9F9', 'borderTop':'1px solid #FFF', 'borderRight':'1px solid #888', 'borderBottom':'1px solid #666', 'borderLeft':'1px solid #FFF', 'top':'50px', 'left':'10%', 'right':'10%', 'bottom':'50px', 'position':'fixed', 'zIndex':2147483647});
		document.body.appendChild(a);

		var b = document.createElement('div');		// header
		set_style(b, {'height':'28px', 'backgroundColor':'#369', 'borderBottom':'1px solid #CCC'});
		a.appendChild(b);
		var c = document.createElement('a');		// logo
		set_style(c, {'margin':'8px 0 0 0', 'padding':'0 20px', 'styleFloat':'left'});
		c.setAttribute('href', 'http://uread.me');
		c.setAttribute('title', 'uRead.Me');
		c.setAttribute('target', '_blank');
		var d = document.createElement('img');		// logo image
		set_style(d, {'cursor':'pointer', 'width':'96px', 'height':'12px'});
		d.setAttribute('src', 'http://uread.me/images/logo_small.png');
		c.appendChild(d);
		b.appendChild(c);
		c = document.createElement('a');		// close
		set_style(c, {'color':'#ACF', 'fontSize':'14px', 'margin':'8px 0 0 30px', 'padding':'0 15px', 'styleFloat':'right', 'cursor':'pointer'});
		c.appendChild(document.createTextNode("X")); 
		c.onclick		= function () { close_layer(); }
		b.appendChild(c);
		c = document.createElement('a');		// exit
		set_style(c, {'color':'#ACF', 'margin':'9px 0 0 30px', 'padding':'0 15px', 'styleFloat':'right', 'cursor':'pointer'});
		c.setAttribute('id', 		'uReadMe_exit');
		c.onclick		= function () { jsonp_call_server('logout'); }
		b.appendChild(c);
		c = document.createElement('a');		// nick
		set_style(c, {'color':'#ACF', 'margin':'9px 0 0 0', 'padding':'0 15px', 'styleFloat':'right'});
		c.setAttribute('id', 		'uReadMe_nick');
		c.setAttribute('href', 		'http://uread.me');
		c.setAttribute('target', 	'_blank');
		b.appendChild(c);
		c = document.createElement('div');		// icon not login
		set_style(c, {'display':'inline-block', 'styleFloat':'right', 'margin':'8px 0 0 0'});
		c.setAttribute('id', 		'uReadMe_not_login');
		b.appendChild(c);
		c = document.createElement('div');		// icon is login
		set_style(c, {'display':'inline-block', 'styleFloat':'right', 'margin':'8px 0 0 0'});
		c.setAttribute('id', 		'uReadMe_is_login');
		b.appendChild(c);

		
		c = document.createElement('div');
		c.setAttribute('id', 		'uReadMe_content');
		set_style(c, {'backgroundColor':'#FFFFFF', 'height':(a.clientHeight-b.clientHeight-1)+'px'});
		a.appendChild(c);

		return c;
	}
	close_layer = function () {
		var b = document.getElementById('uReadMe_bg');
		if (b) {
			b.removeNode(true);
			//document.body.removeChild(b);
		} 
		var f = document.getElementById('uReadMe_fg');
		if (f) {
			f.removeNode(true);
			//document.body.removeChild(f);
		}
	}
	save = function () {
		if (hs) {
			var i	= 0;
			var ob 	= null;
			
			// 先检查是否选定了circle
			ob = document.getElementById('uReadMe_circle_list').childNodes;
			var c = '';
			for (i=0; i<ob.length; i++) {
				if (typeof(ob[i].attributes.uReadMeId) == 'object' && color2hex(ob[i].style.backgroundColor) != 'transparent') {  c += ob[i].attributes.uReadMeId.value + ',';  }
			}
			var cn = document.getElementById('uReadMe_new_circle_name').value;
			var cp = (document.getElementById('uReadMe_new_circle_is_private').checked) ? '1' : '';
			
			if (c || cn) {
				// 隐藏save button
				var s = document.getElementById('uReadMe_save_button');
				s.style.display = 'none';
				
				// 显示wating，隐藏body ......................................
				var bd = document.getElementById('uReadMe_body');
				var p = bd.parentNode;
				bd.style.display = 'none';
	
				var wating = document.createElement('div');
				set_style(wating, {'fontSize':'24px', 'fontFamily':'微软雅黑,黑体', 'color':'#ACF', 'padding':'100px 0 0 0', 'textAlign':'center'});
				wating.appendChild(document.createTextNode("操作中，请稍候...")); 
				p.appendChild(wating);
				
				// -- 获得save页面中的其他各个表单数据 -----------------------------------------------------------
				ob = document.getElementById('uReadMe_friend_list').childNodes;
				var f = '';
				for (i=0; i<ob.length; i++) {
					if (typeof(ob[i].attributes.uReadMeId) == 'object' && color2hex(ob[i].style.backgroundColor) != 'transparent') {  f += ob[i].attributes.uReadMeId.value + ',';  }
				}
				
				bd.innerHTML = '';	// 获取完数据后清空吧
				bd.removeNode(true);
				//p.removeChild(bd);
				
				// -- Iframe and Form post  -----------------------------------------------------------
				var ifr_div = document.createElement('div');
				set_style(ifr_div, {'display':'none'});
				p.appendChild(ifr_div);
				// 注：用createElement创建之后，ie无法识别name属性，只能用innerHTML的方式写入
				ifr_div.innerHTML = '<iframe id="uReadMeSaveIframe" name="uReadMeSaveIframe" src=""  frameborder="0"></iframe>';
				// Form
				var fm = document.createElement('form');
				fm.setAttribute('method', 	'POST');
				fm.setAttribute('action', 	hst+'/save.php');
				fm.setAttribute('target', 	'uReadMeSaveIframe');
				create_hidden_input(fm, 'br', 	'ie');
				create_hidden_input(fm, 'u', 	str_filter(document.URL));
				create_hidden_input(fm, 't', 	str_filter(document.title));
				create_hidden_input(fm, 'hs', 	str_filter(hs));
				create_hidden_input(fm, 'cn', 	str_filter(cn));
				create_hidden_input(fm, 'cp', 	cp);
				create_hidden_input(fm, 'f', 	f);
				create_hidden_input(fm, 'c', 	c);
				p.appendChild(fm);
				
				var ifr = document.getElementById('uReadMeSaveIframe');
				set_style(ifr, {'display':'block', 'width':'100%', 'height':(document.getElementById('uReadMe_content').clientHeight - document.getElementById('uReadMe_title').clientHeight - 12)+'px'});
				var iTimes = 0;
				ifr.onreadystatechange = function () {
					if (ifr.readyState == 'complete') {
						iTimes++;
						if (iTimes == 1) {
							fm.submit();
						} else if (iTimes == 2) {
							waiting.removeNode(true);
							//p.removeChild(wating);
							fm.removeNode(true);
							//p.removeChild(fm);
							ifr_div.style.display = 'block';
						}
					}
				}
			} else {
				alert('请选择一个阅读圈');
			}
		} else {
			create_error('无法获取页面内容，请刷新页面重新再试！');
		}
	}
	create_hidden_input = function (fm, id, value) {
		var input = document.createElement("input");
		input.setAttribute("type", 	"hidden");
		input.setAttribute("id", 	id);
		input.setAttribute("name", 	id);
		input.setAttribute("value", value);
		fm.appendChild(input);
	}
	get_selection_HTML = function () {
		var s = document.selection.createRange().htmlText.replace(/<style(.|\n|\r)+?<\/style>|<link.+?>|<script(.|\n|\r)+?<\/script>|<iframe(.|\n|\r)+?<\/iframe>|<!--(.|\n|\r)+?-->|<form(.|\n|\r)+?<\/form>/gim, "");
		if (s) {
			// parse STYLE and LINK from all HTML(Maybe part of), then add to selection
			var parser = document.body.parentNode.outerHTML.match(/<style(.|\n|\r)+?<\/style>|<link.+?>/gim);
			for (var i=0; i<parser.length; i++) {
				s = parser[i] + s;
			}
			return s;
		} else return '';
	}
	get_all_HTML = function () {
		return document.body.parentNode.outerHTML.replace(/<script(.|\n|\r)+?<\/script>|<iframe(.|\n|\r)+?<\/iframe>|<!--(.|\n|\r)+?-->|<form.*?>|<\/form>|<input.*?>/gim, "");
	}
	set_style = function (ob, style) {
		var s = {
			"backgroundAttachment" : "scroll",
			"backgroundColor" : "transparent",
			"backgroundImage" : "none",
			"backgroundPosition" : "0% 0%",
			"backgroundRepeat" : "repeat",
			"backgroundClip" : "border-box",
			"backgroundOrigin" : "padding-box",
			"backgroundSize" : "auto",
			"borderTop" : "medium none transparent",
			"borderLeft" : "medium none transparent",
			"borderRight" : "medium none transparent",
			"borderBottom" : "medium none transparent",
			"borderCollapse" : "separate",
			"borderSpacing" : "",
			"color" : "#000000",
			"fontFamily" : "Arial",
			"fontSize" : "12px",
			"fontSizeAdjust" : "none",
			"fontStretch" : "normal",
			"fontStyle" : "normal",
			"fontVariant" : "normal",
			"fontWeight" : "400",
			"textAutospace" : "none",
			"textJustifyTrim" : "",
			"textKashida" : "0%",
			"textKashidaSpace" : "0%",
			"textAlign" : "left",
			"textDecoration" : "none",
			"textIndent" : "0pt",
			"textTransform" : "none",
			"textAlignLast" : "auto",
			"textJustify" : "auto",
			"textOverflow" : "clip",
			"textUnderlinePosition" : "auto",
			"wordBreak" : "normal",
			"wordWrap" : "",
			"wordSpacing" : "normal",
			"letterSpacing" : "normal",
			"lineHeight" : "normal",
			"whiteSpace" : "normal",
			"listStyle" : "",
			"width" : "auto",
			"height" : "auto",
			"maxHeight" : "none",
			"maxWidth" : "none",
			"minHeight" : "auto",
			"minWidth" : "auto",
			"margin" : "0",
			"padding" : "0px",
			"top" : "auto",
			"left" : "auto",
			"right" : "auto",
			"bottom" : "auto",
			"clear" : "none",
			"cursor" : "auto",
			"display" : "block",
			"position" : "static",
			"styleFloat" : "none",
			"visibility" : "inherit",
			"zIndex" : "auto",
			"verticalAlign" : "auto",
			"overflow" : "visible",
			"overflowX" : "visible",
			"overflowY" : "visible",
			"filter" : "",
			"opacity" : "1",
			"clip" : "rect(auto,auto,auto,auto)",
			"clipPath" : "none",
			"clipRule" : "nonzero",
			"layoutFlow" : "horizontal",
			"layoutGrid" : "",
			"layoutGridChar" : "none",
			"layoutGridLine" : "none",
			"layoutGridMode" : "both",
			"layoutGridType" : "loose",
			"scrollbar3dLightColor" : "#e3e3e3",
			"scrollbarArrowColor" : "#000000",
			"scrollbarBaseColor" : "#000000",
			"scrollbarDarkShadowColor" : "#696969",
			"scrollbarFaceColor" : "#f0f0f0",
			"scrollbarHighlightColor" : "#ffffff",
			"scrollbarShadowColor" : "#a0a0a0",
			"scrollbarTrackColor" : "",
			"outline" : "#000000 0px none",
			"outlineColor" : "#000000",
			"outlineStyle" : "none",
			"outlineWidth" : "0px",
//			"counterIncrement" : "",
//			"counterReset" : "",
			"pageBreakAfter" : "auto",
			"pageBreakBefore" : "auto",
			"pageBreakInside" : "auto",
			"borderRadius" : "0px",
			"borderBottomLeftRadius" : "0px",
			"borderBottomRightRadius" : "0px",
			"borderTopLeftRadius" : "0px",
			"borderTopRightRadius" : "0px",
			"boxShadow" : "none",
			"boxSizing" : "content-box",
			"rubyAlign" : "auto",
			"rubyOverhang" : "auto",
			"rubyPosition" : "above",
			"content" : "normal",
			"blockDirection" : "ltr",
			"hasLayout" : false,
			"accelerator" : false,
			"behavior" : "",
			"imeMode" : "",
			"lineBreak" : "normal",
			"msBlockProgression" : "tb",
			"msInterpolationMode" : "",
			"writingMode" : "lr-tb",
			"zoom" : "normal",
			"captionSide" : "top",
			"direction" : "ltr",
			"emptyCells" : "show",
			"orphans" : "2",
			"tableLayout" : "auto",
			"unicodeBidi" : "normal",
			"widows" : "2",
			"alignmentBaseline" : "auto",
			"baselineShift" : "baseline",
			"dominantBaseline" : "auto",
			"fill" : "black",
			"fillOpacity" : "1",
			"fillRule" : "nonzero",
			"glyphOrientationHorizontal" : "0deg",
			"glyphOrientationVertical" : "auto",
			"kerning" : "auto",
			"marker" : "none",
			"markerEnd" : "none",
			"markerMid" : "none",
			"markerStart" : "none",
			"mask" : "none",
			"pointerEvents" : "visiblePainted",
			"stopColor" : "",
			"stopOpacity" : "1",
			"stroke" : "",
			"strokeDasharray" : "none",
			"strokeDashoffset" : "0px",
			"strokeLinecap" : "butt",
			"strokeLinejoin" : "miter",
			"strokeMiterlimit" : "4",
			"strokeOpacity" : "1",
			"strokeWidth" : "0.01px",
			"textAnchor" : "start"
		};
		if (ob.tagName == 'A') {
			s["display"] = "inline";
		} else if (ob.tagName == 'SELECT') {
			s["display"] = "inline-block";
			s["backgroundColor"] = "#ffffff";
			s["borderTop"] = "1px none transparent",
			s["borderLeft"] = "1px none transparent",
			s["borderRight"] = "1px none transparent",
			s["borderBottom"] = "1px none transparent",
			s["boxSizing"] = "border-box";
			s["overflow"] = "hidden";
			s["overflowX"] = "hidden";
			s["overflowY"] = "hidden";
		} else if (ob.tagName == 'INPUT' && ob.type == 'text') {
			s["display"] = "inline-block";
			s["backgroundColor"] = "#ffffff";
			s["borderTop"] = "2px none transparent",
			s["borderLeft"] = "2px none transparent",
			s["borderRight"] = "2px none transparent",
			s["borderBottom"] = "2px none transparent",
			s["padding"] = "1px";
			s["overflow"] = "hidden";
			s["overflowX"] = "hidden";
			s["overflowY"] = "hidden";
		} else if (ob.tagName == 'INPUT' && ob.type == 'radio') {
			s["display"] = "inline-block";
			s["padding"] = "3px";
		} else if (ob.tagName == 'INPUT' && ob.type == 'checkbox') {
			s["display"] = "inline-block";
			s["padding"] = "3px";
		} else if (ob.tagName == 'INPUT' && ob.type == 'button') {
			s["display"] = "inline-block";
			s["backgroundColor"] = "#f0f0f0";
			s["borderTop"] = "3px none transparent",
			s["borderLeft"] = "3px none transparent",
			s["borderRight"] = "3px none transparent",
			s["borderBottom"] = "3px none transparent",
			s["padding"] = "1px 8px";
			s["textAlign"] = "center";
			s["boxSizing"] = "border-box";
			s["overflow"] = "hidden";
			s["overflowX"] = "hidden";
			s["overflowY"] = "hidden";
		} else if (ob.tagName == 'IFRAME') {
			s["display"] = "inline";
		}
		
		for (var a in style) {
			s[a] = style[a];
		}
                
		for (var b in s) {
                    if (typeof(ob.style[b]) != 'undefined') {
                        ob.style[b] = s[b];
                    }
		}
	}	
	str_filter = function (str) {
		str = str.replace(/<script.+?<\/script>|<style.+?<\/style>|<iframe.+?<\/iframe>|<!--.+?-->|<form.+?>|<\/form>/gim, "");
		str = str.replace(/\'/gim, "NjhUy6OpFdeAqmLK");
		str = str.replace(/\"/gim, "kJuh6gXde3ScfoYR");
		return encodeURIComponent(str);
	}
	color2hex = function (colorStr) {
		var ret = "#";
		var tmp = '';
		var i = 0;
		if (colorStr == "transparent" || colorStr.substring(0, 1) == "#") {
			return colorStr;
		} else if (colorStr.substring(0, 4) == "rgb(") {
			colorStr = colorStr.substring(4, (colorStr.length - 1));
			colorStr = colorStr.split(",");
			for (i=0; i<3; i++) {
				tmp = parseInt(colorStr[i], 10).toString(16).toUpperCase();
				if (tmp.length == 1) {
					tmp = "0" + tmp;
				}
				ret += tmp;
			}
			return ret;
		} else if (colorStr.substring(0,5) == "rgba(") {
			colorStr = colorStr.substring(5, (colorStr.length - 1));
			colorStr = colorStr.split(",");
			if (colorStr[3] == 0) {
				return 'transparent';
			} else {
				for (i=0; i<3; i++) {
					tmp = parseInt(colorStr[i], 10).toString(16).toUpperCase();
					if (tmp.length == 1) {
						tmp = "0" + tmp;
					}
					ret += tmp;
				}
				return ret;
			}
		} else {
			return false;
		}
	}
	float_social = function (act, ob) {
		var v = ob.attributes.uReadMeSocials.value;
		if (typeof(v) == 'string' && v.length>0) {
			var c = document.getElementById('uReadMe_social_float');
			if (!c) {
				c = document.createElement('div');
				c.setAttribute('id', 	'uReadMe_social_float');
                                set_style(c, {'display':'none', 'position':'absolute', 'whiteSpace':'nowrap', 'top':0, 'left':0, 'backgroundColor':'#FFE', 'padding':'5px 10px', 'border':'1px solid #CCC'});
				var d = document.createElement('img');
				d.setAttribute('id', 	'uReadMe_social_weibo');
				d.setAttribute('src', 	'http://uread.me/images/icon_weibo_16.png');
                                set_style(d, {'display':'none', 'width':'16px', 'height':'16px', 'margin':'5px', 'verticalAlign':'middle'});
				c.appendChild(d);
				d = document.createElement('img');
				d.setAttribute('id', 	'uReadMe_social_renren');
				d.setAttribute('src', 	'http://uread.me/images/icon_renren_16.png');
				set_style(d, {'display':'none', 'width':'16px', 'height':'16px', 'margin':'5px', 'verticalAlign':'middle'});
				c.appendChild(d);
				d = document.createElement('img');
				d.setAttribute('id', 	'uReadMe_social_kaixin001');
				d.setAttribute('src', 	'http://uread.me/images/icon_kaixin001_16.png');
				set_style(d, {'display':'none', 'width':'16px', 'height':'16px', 'margin':'5px', 'verticalAlign':'middle'});
				c.appendChild(d);
				d = document.createElement('img');
				d.setAttribute('id', 	'uReadMe_social_qqwb');
				d.setAttribute('src', 	'http://uread.me/images/icon_qqwb_16.png');
				set_style(d, {'display':'none', 'width':'16px', 'height':'16px', 'margin':'5px', 'verticalAlign':'middle'});
				c.appendChild(d);
				d = document.createElement('span');
				d.setAttribute('id', 	'uReadMe_social_name');
                                set_style(d, {'display':'none','margin':'5px', 'verticalAlign':'middle'});
				c.appendChild(d);
				document.getElementById('uReadMe_friend_list').appendChild(c);
			}
			if (act == 'show') {
				var s = v.split('_');
				for (var i=0; i<s.length; i++) {
					document.getElementById('uReadMe_social_' + s[i]).style.display = 'inline-block';
				}
				document.getElementById('uReadMe_social_name').innerHTML = ob.innerHTML;
				document.getElementById('uReadMe_social_name').style.display = 'inline-block';
				c.style.display = 'block';
//                                document.getElementById('uReadMe_social_name').innerHTML = 'ob.offsetTop = ' + ob.offsetTop + ', me body.scrolltop = ' + document.getElementById('uReadMe_body').scrollTop + ', c.height = ' + c.clientHeight;
				c.style.top  = (ob.offsetTop - c.clientHeight + 3) + 'px';
				c.style.left  = (ob.offsetLeft) + 'px';
			} else {
				c.style.display = 'none';
				document.getElementById('uReadMe_social_name').style.display = 'none';
				document.getElementById('uReadMe_social_weibo').style.display = 'none';
				document.getElementById('uReadMe_social_renren').style.display = 'none';
				document.getElementById('uReadMe_social_kaixin001').style.display = 'none';
				document.getElementById('uReadMe_social_qqwb').style.display = 'none';
			}
		}
	}
}
UM_OB.opn();